// /////////////////////////////////////////////////////////////////////////////
//
// Name:            EntityProcessor.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Declaration of the EntityProcessor class.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __ENTITYPROCESSOR_H__
#define __ENTITYPROCESSOR_H__

// Include files
#include "../dependencies.h"
#include "../core/AssetProcessor.h"
#include "../core/EntityManager.h"


// EntityProcessor class
//! AssetProcessor for processing entities in an AssetGroup.
class EntityProcessor : public AssetProcessor
{
public:

    // Initialisation and deinitialisation
    //! Constructor
    EntityProcessor(AssetGroup *parent);
    //! Deconstructor
    ~EntityProcessor();

    // Public methods
    //! Gets the entity with the given filename.
    //! @param fileName      Filename of the mesh.
    Entity* getEntity(const std::string &fileName);

    //! Gets the entire entity tree with the given entity as root.
    //! @param root          Root entity of the tree
    //! @note Existing parents are NOT overridden.
    void getEntityTree(Entity *root);

    //! Reloads the asset with the given filename.
    //! @param fileName      Filename of the asset.
    //! @return True on succesful removal, false otherwise.
    bool reloadAsset(const std::string &fileName);
    //! Reloads all assets.
    void reloadAssets();

    //! Removes the asset with the given filename.
    //! @param fileName      Filename of the asset.
    //! @return True on succesful removal, false otherwise.
    bool removeAsset(const std::string &fileName) ;
    //! Removes all assets.
    void removeAssets();

    //! Creates a new EntityProcessor.
    //! @note For internal use only!
    static AssetProcessor* createProcessor(AssetGroup *parent);

protected:

    // Protected methods
    //! Loads the asset with the given filename.
    //! @param fileName      Filename of the asset.
    //! @return True on succesful loading, false otherwise.
    bool loadAsset(const std::string &fileName);
    //! Loads all assets.
    void loadAssets();


private:

    // Private members
    std::map<std::string, std::pair<c8*, long> > mEntityFiles;
    std::map<std::string, Entity*> mEntities;

    bool mIsReloading;
};

#endif
